package com.lb.jdbc;

import java.sql.*;

/**
 * 增加操作
 */

public class Insert {

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //1.注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取Java与数据库的连接对象
        Connection conn = DriverManager.getConnection("jdbc:mysql://120.77.241.104:3306/libo?useSSL=false","root","ROOT_root_1234");
        //3.获取执行sql语句的对象
        Statement statement = conn.createStatement();
        //4.定义sql语句
        String sql = "INSERT INTO emp VALUES(7369,'张三','总监','2019-10-09','1501')";
        //5.执行sql语句【返回值结果代表我们的sql语句影响的行数】
        int count = statement.executeUpdate(sql);
        System.out.println("count::"+count);
        //6.处理我们的结果
        if (count > 0) {
            System.out.println("增加数据成功！");
        }else {
            System.out.println("增加数据失败！");
        }
        //7.释放资源
        conn.close();
        statement.close();
    }
}
